<template>
	<view class="warpbox">
		<!-- 搜索 -->
		<!-- <view class="searbox">
			<view class="censear">
				<image :src="BASE_IMG_URL+'/index/search.png'" class="searimg" ></image>
				<input type="text" placeholder="请输入关键词搜索" @input="queryData" class="lself" placeholder-style="color:#999">
			</view>
		</view> -->
		<!-- 搜索 -->
		<search-box @queryData="queryData" @showModal="showSc"></search-box>
		<scroll-view scroll-y class="scrollbox">
			<view class="pop_info_right">
				<view class="pop_info_cen" v-for="(item,index) in list" :key="index">
					<view class="pro_top">
						<view class="cont_left">
							<view class="cont_num">订单单号：<text class="pro_title" @click="toOrder(item)">{{item.purchase_code}}</text></view>
						</view>
						<view class="con_status" style="display: flex;align-items: center;">
							{{item.staff_member.name}}
							<image :src="item.staff_member.avatar" class="staffimg"></image>
						</view>
					</view>
					<view class="pro_info">
						<view class="image">
							<image :src="item.goods_image" class="proimg" ></image>
						</view>
						<view class="pro_info_right">
							<view class="info_text" style="font-size: 28rpx; color: #666;">{{item.goods_name}}</view>
							<view class="space-between">
								<view>
									<view class="info_text">编码：{{item.goods_code}}</view>
									<view class="info_text">销售单价：{{item.price}}</view>
									<view class="info_text">返款金额：{{item.back_money}}</view>
								</view>
								<view>
									<view class="info_text">单位：{{item.goods_unit}}</view>
									<view class="info_text">数量：{{item.number}}</view>
									<view class="info_text">购买类型：{{item.goods_type}}</view>
								</view>
							</view>
							<view class="info_text">关联客户：<text class="cus_name_a" @click="toCustomer(item)">{{item.customer_name}}</text></view>
							<view class="info_text" v-if="item.serial != ''">锁号：{{item.serial}}</view>
						</view>
					</view>
				</view>
			</view>
		</scroll-view>
		<!-- 订单金额统计 -->
		<!-- <view class="bot_total" @click="lookTotal">总金额合计> </view>
		
		<uni-popup ref="popupTotal" type="bottom" background-color="#fff">
			<view class="botwarp">
				<view class="wa_li">
					<view class="wa_label">累计订单总金额</view>
					<view class="wa_money"> <text>{{moneyInfo.allmoney?moneyInfo.allmoney:'0'}}</text>元 </view>
				</view>
				<view class="wa_li">
					<view class="wa_label">累计返款金额</view>
					<view class="wa_money"> <text>{{moneyInfo.back_money?moneyInfo.back_money:'0'}}</text>元 </view>
				</view><view class="wa_li">
					<view class="wa_label">累计已回款金额</view>
					<view class="wa_money"> <text>{{moneyInfo.repayment_money?moneyInfo.repayment_money:'0'}}</text>元 </view>
				</view>
				<view class="wa_li">
					<view class="wa_label">累计未回款金额</view>
					<view class="wa_money"> <text>{{moneyInfo.be_money?moneyInfo.be_money:'0'}}</text>元 </view>
				</view>
				<view class="wa_btn" @click="removeTotal">取消</view>
			</view>
		</uni-popup> -->
		
		<screen-pop 
			ref="screenChild" 
			@sureQuery="sureQuery"
			:searchForm="searchForm"
			@changeSearchData="changeSearchData"
			@resetForm="resetForm"
		></screen-pop>
	</view>
</template>

<script>
	import { netProductList,netOrderGoodsList } from '@/api/api.js'
	import { BASE_IMG_URL } from '@/api/http.js'
	import screenPop from './screenPop.vue'
	
	export default{
		components:{
			screenPop
		},
		data(){
			return{
				BASE_IMG_URL:BASE_IMG_URL,
				list:[],
				page:1,
				totalPage:1,
				name:'',
				searchForm:null,  //搜索表单
				defaultObj:{type:'',times:'',check_status:''},
				moneyInfo:{},
			}
		},
		onLoad() {
			this.$store.commit('CUSTOMEROBJ',null)
			this.$store.commit('STAFFOBJ',null)
			//获取搜索表单
			this.getSearchForm()
		},
		onShow() {
			this.init()
		},
		onReachBottom() {
			if(this.page >= this.totalPage){
				return
			}
			this.page ++
			this.getList()
		},
		methods:{
			init(){
				this.page = 1
				this.list = []
				this.getList()
			},
			queryData(e) {
				this.name = e.detail.value
				this.init()
			},
			//搜索表单
			getSearchForm() {
				this.handleSearchForm('contract',(data)=>{
					this.searchForm = data
				})
			},
			changeSearchData(type,key,value){
				let arr = this.searchForm
				arr.forEach((ele,index)=>{
					if(ele.field == type){
						ele[key] = value
						this.$set(this.searchForm, index, ele)
					}
				})
			},
			resetForm() {
				this.searchForm = this.handleResetSearch(this.searchForm)
			},
			showSc() {
				this.$refs.screenChild.open(this.defaultObj)
			},
			sureQuery(params) {
				this.queryObj = params
				this.defaultObj = {
					type: params.type,
					times: params.createtime,
					check_status: params.check_status
				}
				this.init()
			},
			getList() {
				let params = {
					page:this.page,
					name:this.name,
					...this.queryObj
				}
				netOrderGoodsList(params).then(res=>{
					this.list = this.list.concat(res.data.data)
					this.totalPage = res.data.last_page
				})
			},
			// toAddProduct() {
			// 	uni.navigateTo({
			// 		url:'/pages/index/productManagements/addProduct?type=1'
			// 	})
			// },
			toDetail(item) {
				uni.navigateTo({
					url:'/pages/index/productManagements/addProduct?type=2&id='+item.id
				})
			},
			toCustomer(item) {
				uni.navigateTo({
					url:'/pagesA/customerInfo/myCustomer/customerDetail?customerid='+item.customers_id
				})
			},
			toOrder(item) {
				uni.navigateTo({
					url:'/pages/index/contractManagements/contractDetail?id='+item.order_id+'&purchase_code='+item.purchase_code
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.searbox{
		padding:10rpx 0 20rpx 0;
		display: flex;
		justify-content: center;
		align-items: center;
		background:$uni-top-bg-color;
		.censear{
			display: flex;
			justify-content: flex-start;
			align-items: center;
			padding:0 24rpx;
			border-radius: 34rpx;
			background:#FFFFFF;
			width:488rpx;
			height:68rpx;
			.searimg{
				padding-right: 15rpx;
				width:35rpx;
				height:35rpx;
			}
			.lself{
				font-size:26rpx;
			}
		}
	}
	.scrollbox{
		width:750rpx;
		height:calc(100vh - 110rpx);
	}
	.pop_info_right{
		padding:24rpx 0;
		.pop_info_cen{
			width: 690rpx;
			background: #FFFFFF;
			box-shadow: 0px 0px 7rpx 0px rgba(0, 0, 0, 0.15);
			border-radius: 10rpx;
			margin:24rpx auto 0;
			.pro_top{
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding:10rpx 24rpx;
				border-bottom:1rpx solid #EDEDED;
				.cont_left{
					display: flex;
					justify-content: flex-start;
					align-items: center;
					.labelimg{
						width:40rpx;
						height:40rpx;
						margin-right:20rpx;
					}
					.cont_num{
						font-size:28rpx;
						color:#666666;
					}
				}
				.con_status{
					font-size:22rpx;
					color:#999;
					padding:0 15rpx;
					image{
						width: 56rpx;
						height: 56rpx;
					}
				}
			}
			.staffimg{
				width:40rpx;
				height:40rpx;
				border-radius: 50%;
				margin-left:15rpx;
			}
		}
		.pro_title{
			font-size:30rpx;
			color:$uni-text-color;
		}
		.pro_info{
			display: flex;
			justify-content: flex-start;
			align-items: center;
			padding:24rpx;
			.image{
				// margin: 33rpx 0 33rpx 30rpx;
				// width: 158rpx;
				// height: 158rpx;
				width: 30%;
			}
			.proimg{
				// margin: 33rpx 0 33rpx 30rpx;
				width: 158rpx;
				height: 158rpx;
				border-radius: 10rpx;
			}
			.pro_info_right{
				margin-left: 40rpx;
				width: 70%;
				.info_text{
					font-size:26rpx;
					color:#999999;
					margin:6rpx 0;
					&:last-child{
						margin-bottom:0;
						margin-top:10rpx;
					}
				}
				.cus_name_a{
					font-size: 26rpx;
					color: $uni-text-color;
					overflow: hidden;
					text-overflow: ellipsis;
					// white-space: nowrap;
				}
			}
		}
		.pro_num{
			font-size:28rpx;
			color:#0287FF;
			padding:24rpx 0;
		}
	}
	.icon_creat {
		position: fixed;
		z-index: 1;
		bottom: 100rpx;
		right: 100rpx;
		image {
			width: 80rpx;
			height: 80rpx;
			border-radius: 50%;
		}
	}
	.space-between{
		display: flex;
		justify-content: space-between;
		align-items: center;
	}
</style>
